<?php
use_helper('I18N');
?>
<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try {
            ace.settings.check('breadcrumbs', 'fixed')
        } catch(e) {
        }

        $(function() {
            $("#submitLink").click(function(event){
                event.preventDefault();
                var answer = confirm("<?php echo __('Are you sure you want to funds deposit?')?>")
                if (answer == true) {
                    $("#transferForm").submit();
                }
            });
            $("#transferForm").validate({
                messages : {
                    transactionPassword: {
                        remote: "<?php echo __("Security Password is not valid")?>"
                    }
                },
                rules : {
                    "bankSlip" : {
                        required : true
                        , accept:true
                    },
                    "fundAmount" : {
                        required : true
                    },
                    "transactionPassword" : {
                        required : true,
                        remote: "/member/verifyTransactionPassword"
                    }
                },
                submitHandler: function(form) {
                    waiting();
                    var amount = $('#fundAmount').autoNumericGet();
                    $("#fundAmount").val(amount);
                    form.submit();
                }
            });
            $('#fundAmount').autoNumeric({
                mDec: 2
            });

            $('#paymentMethod').change(function(){
                var paymentMethod = $(this).val();
                if (paymentMethod == "GOZ") {
                    $("#tr_channelid").show();
                } else {
                    $("#tr_channelid").hide();
                }
            });

            /*$("#dgBankReceipt").dialog("destroy");
            $("#dgBankReceipt").dialog({
                autoOpen : false,
                modal : true,
                resizable : false,
                hide: 'clip',
                show: 'slide',
                width: 700,
                height: 430,
                buttons: {
                    "<?php echo __('Print') ?>": function() {
                        var params  = 'width=891';
                        params += ', height=637';
                        params += ', top=0, left=0';

                        newwin = window.open("<?php echo url_for("/member/printBankInformation?q=1231j32lkhljkewrw&p=")."/";?>" + $("#purchaseId").val(),'Bank Information', params);
                        if (window.focus)
                        {
                            newwin.focus();
                        }
                    }
                    *//*, "<?php //echo __('Submit') ?>": function() {
                        $("#uploadForm").submit();
                    }*//*
                },
                open: function() {
                },
                close: function() {

                }
            });*/

            <?php if ($sf_flash->has('successMsg') && $pg == "N") { ?>
                /*$("#dgBankReceipt").dialog("open");*/
            <?php } ?>
        });
</script>
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="/member/memberRegistration"><?php echo __('Registration') ?></a>
        </li>
        <li class="active"><?php echo __('Funds Deposit') ?></li>
    </ul>
    <!-- .breadcrumb -->

    <div class="nav-search" id="nav-search">
        <form class="form-search">
            <span class="input-icon">
                <input type="text" placeholder="Search ..." class="nav-search-input"
                       id="nav-search-input" autocomplete="off"/>
                <i class="icon-search nav-search-icon"></i>
            </span>
        </form>
    </div>
    <!-- #nav-search -->
</div>
    
    <div class="page-content">
<!--<div class="page-header">
    <h1>
        <?php /*echo __('Registration') */?>
        <small>
            <i class="icon-double-angle-right"></i>
            <?php /*echo __('Funds Deposit') */?>
        </small>
    </h1>
</div>-->
<!-- /.page-header -->

<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->

<?php include_component('component', 'alert', array('param' => $sf_user->getAttribute(Globals::SESSION_DISTID, 0))) ?>

<div class="row">
<div class="space-6"></div>

<div class="col-xs-12">
    <form action="/member/fundsDeposit" id="transferForm" name="transferForm" method="post" class="form-horizontal" role="form">
        <h3 class="header smaller lighter green"><?php echo __('Funds Deposit') ?></h3>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="memberId"><?php echo __('Member ID'); ?></label>

            <div class="col-sm-9">
                <input name="memberId" type="text" id="memberId" 
                       placeholder="<?php echo __('Member ID'); ?>" readonly="readonly" value="<?php echo $distDB->getDistributorCode(); ?>" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="fullname"><?php echo __('Full Name'); ?></label>

            <div class="col-sm-9">
                <input name="fullname" type="text" id="fullname" 
                       placeholder="<?php echo __('Full Name'); ?>" readonly="readonly" value="<?php echo $distDB->getFullname(); ?>" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="fundAmount"><?php echo __('Total Fund Deposited'); ?></label>

            <div class="col-sm-9">
                <input name="fundAmount" type="text" id="fundAmount" 
                       placeholder="<?php echo __('Total Fund Deposited'); ?>" value="" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="fundAmount"><?php echo __('Deposit to'); ?></label>

            <div class="col-sm-9">
                    <select name="walletType" id="walletType">
                    <?php
                        if ($mlmIb) {
                    ?>
                            <option value="<?php echo Globals::ACCOUNT_TYPE_EPOINT; ?>"><?php echo __("Register Point");?></option>
                    <?php
                        }
                    ?>
                        <option value="<?php echo Globals::ACCOUNT_TYPE_MG; ?>"><?php echo __("MG");?></option>
                        <option value="<?php echo Globals::ACCOUNT_TYPE_MP; ?>"><?php echo __("MP");?></option>
                    </select>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="fundAmount"><?php echo __('Payment Method'); ?></label>

            <div class="col-sm-9">
                <?php
                    /*$disabled = "";
                    if ($distDB->getDistributorId() == 1) {

                    } else {
                        $disabled = "disabled='disabled'";
                    }*/
                    ?>
                    <select name="paymentMethod" id="paymentMethod">
                        <option value="GOZ"><?php echo __("Online Payment Gateway");?></option>
<!--                        <option value="LB" disabled="disabled">--><?php //echo __("Bank Transfer");?><!--</option>-->
                    </select>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="channelid"><?php echo __('Bank'); ?></label>

            <div class="col-sm-9">
                <select name="channelid" id="channelid">
                    <option value="ABC">中国农业银行</option>
                    <option value="CCB">中国建设银行</option>
                    <option value="CIB">兴业银行</option>
                    <option value="CMB">招商银行</option>
                    <option value="CMBC">民生银行</option>
                    <option value="HXB">华夏银行</option>
                    <option value="ICBC">中国工商银行</option>
                    <option value="BOCSH">中国银行</option>
                    <option value="COMM">交通银行</option>
                    <option value="SPDB">浦发银行</option>
                    <option value="GDB">广发银行</option>
                    <option value="SDB">深圳发展银行</option>
                    <option value="POSTGC">中国邮政储蓄</option>
                    <option value="SHRCB">上海农村商业银行</option>
                    <option value="BOB">北京银行</option>
                    <option value="GZCB">广州商业银行</option>
                    <option value="CEB">光大银行</option>
                    <option value="BOWZ">温州银行</option>
                    <option value="CNCB">中信银行</option>
                </select>
            </div>
        </div>

        <div class="space-4"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="transactionPassword"><?php echo __('Security Password'); ?></label>

            <div class="col-sm-9">
                <input name="transactionPassword" type="password" id="transactionPassword"
                       placeholder="<?php echo __('Security Password'); ?>" value="" class="col-xs-10 col-sm-5" />
            </div>
        </div>

        <div class="space-4"></div>

        <div class="clearfix form-actions">
            <div class="col-md-offset-3 col-md-9">
                <button class="btn btn-info" type="button" id="submitLink">
                    <i class="icon-ok bigger-110"></i>
                    <?php echo __('Submit') ?>
                </button>
            </div>
        </div>
    </form>
</div>

<div class="vspace-sm"></div>

<!-- /span -->
</div>
<!-- /row -->

<div class="hr hr32 hr-dotted"></div>

<!-- /row -->

<script type="text/javascript" language="javascript">
var datagrid = null;
$(function() {
    datagrid = $("#datagrid").r9jasonDataTable({
        // online1DataTable extra params
        "idTr" : true, // assign <tr id='xxx'> from 1st columns array(aoColumns);
        "extraParam" : function(aoData) { // pass extra params to server
        },
        "reassignEvent" : function() { // extra function for reassignEvent when JSON is back from server
            reassignDatagridEventAttr();
        },

        // datatables params
        "bLengthChange": true,
        "bFilter": false,
        "bProcessing": true,
        "bServerSide": true,
        "bAutoWidth": false,
        "sAjaxSource": "/finance/epointPurchaseHistoryList",
        "sPaginationType": "full_numbers",
        "aaSorting": [
            [1,'desc']
        ],
        "aoColumns": [
            { "sName" : "purchase_id", "bVisible" : false,  "bSortable": true},
            { "sName" : "created_on",  "bSortable": true},
            { "sName" : "amount",  "bSortable": true},
            { "sName" : "payment_reference",  "bSortable": true},
            { "sName" : "status_code",  "bSortable": true},
            { "sName" : "remarks",  "bSortable": true},
            { "sName" : "image_src",  "bVisible": false, "fnRender": function ( oObj ) {
                $("#dgBankReceipt").data("data_" + oObj.aData[0], {
                    purchase_id : oObj.aData[0]
                    , created_on : oObj.aData[1]
                    , amount : oObj.aData[2]
                    , payment_reference : oObj.aData[3]
                    , status_code : oObj.aData[4]
                    , remarks : oObj.aData[5]
                    , image_src : oObj.aData[6]
                    , bank_id : oObj.aData[7]
                });
                return "<img src='" + oObj.aData[6] + "' style='display:none'><a class='detailLink' ref='" + oObj.aData[0] + "' href='#'><?php echo __("Details"); ?></a>";
            }},
            { "sName" : "bank_id", "bVisible" : false,  "bSortable": true}
        ]
    });

    $(".detailLink").on("click", function(event) {
        event.preventDefault();
        var data = $("#dgBankReceipt").data("data_" + $(this).attr("ref"));
        $("#depositAmountSpan").html(data.amount);
        $("#paymentReferenceSpan").html(data.payment_reference);
        $("#purchaseId").val(data.purchase_id);
        $("#fancyImageLink").attr("href", data.image_src);
        $("#fancyImageImg").attr("src", data.image_src);

        $("#bankId").val(data.bank_id).change();

        /*$("#dgBankReceipt").dialog("open");*/
    });

    $("#uploadForm").validate({
        messages : {
            transactionPassword: {
                remote: "<?php echo __("Security Password is not valid")?>"
            }
        },
        rules : {
            "bankSlip" : {
                required : true
                , accept:true
            },
            "transactionPassword" : {
                required : true,
                remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            waiting();
            form.submit();
        }
    });

    $("#btnUpload").button({
        icons: {
            primary: "ui-icon-circle-arrow-n"
        }
    });

    $("#bankId").on("change", function() {
        $("#bankSwiftCodeText").html($("#bankId option:selected").attr("bankSwiftCodeText"));
        $("#ibanText").html($("#bankId option:selected").attr("ibanText"));
        $("#bankAccountHolderText").html($("#bankId option:selected").attr("bankAccountHolderText"));
        $("#bankAccountNumberText").html($("#bankId option:selected").attr("bankAccountNumberText"));
        $("#cityOfBankText").html($("#bankId option:selected").attr("cityOfBankText"));
        $("#countryOfBankText").html($("#bankId option:selected").attr("countryOfBankText"));
    });
}); // end function

function reassignDatagridEventAttr() {
}
</script>

<div class="row">
<div class="space-6"></div>

<div class="col-xs-12">
    <h3 class="header smaller lighter green"><?php echo __('Funds Deposit History') ?></h3>

    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover" id="datagrid" border="0" width="100%">
            <thead>
            <tr>
                <th></th>
                <th><?php echo __('Date') ?></th>
                <th><?php echo __('Funds Deposit') ?></th>
                <th><?php echo __('Reference No') ?></th>
                <th><?php echo __('Status') ?></th>
                <th><?php echo __('Remarks') ?></th>
                <th></th>
                <th></th>
            </tr>
            </thead>
        </table>
    </div>

    <div class="space-4"></div>
</div>

<div class="vspace-sm"></div>

<!-- /span -->
</div>

<!-- PAGE CONTENT ENDS -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div><!-- /.page-content -->

<div id="dgBankReceipt" title="<?php echo __('Bank Information Detail') ?>" style="display:none;">
    <?php echo form_tag('member/uploadBankReceipt', array("enctype" => "multipart/form-data", "id" => "uploadForm")) ?>
    <input type="hidden" id="purchaseId" name="purchaseId" value="<?php echo $sf_flash->get('purchaseId'); ?>">

    <?php echo $sf_flash->get('successMsg') ?>
    <p>
    <table cellspacing="0" cellpadding="0" width="650px" style="margin:0 auto">
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Deposit Amount'); ?></strong>
            </td>
            <td class="value" style="color: red">
                <?php echo $systemCurrency." "; ?>
                <span id="depositAmountSpan">
                    <?php echo $sf_flash->get('amount'); ?>
                </span>
            </td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Trading Currency on MT4'); ?></strong>
            </td>
            <td class="value"><?php echo $tradingCurrencyOnMT4; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Bank Name'); ?></strong>
            </td>
            <td class="value"><?php //echo $bankName; ?>
                <select id="bankId" name="bankId">
                    <option value="1" bankSwiftCodeText="<?php echo $bankSwiftCode; ?>" ibanText="<?php echo $iban; ?>" bankAccountHolderText="<?php echo $bankAccountHolder; ?>" bankAccountNumberText="<?php echo $bankAccountNumber; ?>" cityOfBankText="<?php echo $cityOfBank; ?>" countryOfBankText="<?php echo $countryOfBank; ?>"><?php echo $bankName; ?></option>
                    <?php
                    $toHide = true;
                    if ($distDB->getCountry() != "Thailand" && $toHide == false) {?>
                        <option value="2" bankSwiftCodeText="<?php echo $bankSwiftCode2; ?>" ibanText="<?php echo $iban2; ?>" bankAccountHolderText="<?php echo $bankAccountHolder2; ?>" bankAccountNumberText="<?php echo $bankAccountNumber2; ?>" cityOfBankText="<?php echo $cityOfBank2; ?>" countryOfBankText="<?php echo $countryOfBank2; ?>"><?php echo $bankName2; ?></option>
                    <?php } ?>
                </select>
            </td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Bank Swift Code'); ?></strong>
            </td>
            <td class="value" id="bankSwiftCodeText"><?php echo $bankSwiftCode; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('IBAN'); ?></strong>
            </td>
            <td class="value" id="ibanText"><?php echo $iban; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Bank Account Holder'); ?></strong>
            </td>
            <td class="value" id="bankAccountHolderText"><?php echo $bankAccountHolder; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Bank Account Number'); ?></strong>
            </td>
            <td class="value" id="bankAccountNumberText"><?php echo $bankAccountNumber; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('City of Bank'); ?></strong>
            </td>
            <td class="value" id="cityOfBankText"><?php echo $cityOfBank; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Country of Bank'); ?></strong>
            </td>
            <td class="value" id="countryOfBankText"><?php echo $countryOfBank; ?></td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Payment Reference'); ?></strong>
            </td>
            <td class="value">
                <!--<span id="paymentReferenceSpan" style="color: red"><?php /*echo $sf_flash->get('paymentReference'); */?></span>-->
            <!--<br><br>-->Note: <br>Please write at REFERENCE : <span style="color: red">Maxim Capital Limited - 9120028849</span> and payment reference number &nbsp;<span id="paymentReferenceSpan" style="color: red"><?php echo $sf_flash->get('paymentReference'); ?></span>
            </td>
        </tr>
        <tr>
            <td width="160px" class="caption">
                <strong><?php echo __('Upload Bank Receipt'); ?></strong>
            </td>
            <td class="value">
                <?php echo "<a id='fancyImageLink' rel='image_group' href=''>"; ?>
                    <img id='fancyImageImg' onerror="this.src='/images/common/not_available.gif';"
                     src="empty"
                     height="50">
                </a>
                <?php echo input_file_tag('fileNew', array("id" => "bankSlip", "name" => "bankSlip")); ?>
                <button id="btnUpload">Upload Bank Receipt</button>
            </td>
        </tr>
        <tr>
            <td class="caption">
                <strong><?php echo __('Security Password'); ?></strong>
            </td>
            <td class="value">
                <input name="transactionPassword" type="password"/>
            </td>
        </tr>
    </table>
    </form>
</div>